<?php

/*
 *5/7/2011
 * thao tac du lieu tren category
 */
class M_Category extends CI_Model{
    private $_table = 'movie_categories';
    var $_movie_category_id;
    var $_name;
    
    public function __construct() {
        parent::__construct();
    }
    
    /**
     *them 1 loai film moi
     * @param type $categoryName ten loai film
     * @return id cua category vua moi duoc add
     */
    public function newCategory($categoryName){
        $category = array('name' => $categoryName);
        $this->db->insert($this->_tb_categories, $category);
        return $this->db->insert_id(); 
    }
    
    /**
     *kiem tra xem da co category nay chua
     * @param type $categoryName ten
     * @return true neu nhu ton tai, false thi nguoc lai
     */
    public function isCategoryExist($categoryName){
        $query = $this->db->get_where($this->_table, array('name' => $categoryName), 1, 0);
        if($query->num_rows() > 0)
            return true;
        else
            return false;        
    }
    
    /**
     * lay danh sach caegory
     * @return type mang cac category, bao gom ID va name
     */
    public function getCategoryList(){
        $this->db->cache_on();
        $this->db->order_by('order', 'asc');
        $query = $this->db->get($this->_table);        
        return $query->result_array();
    }
}
?>
